#ifndef UTILS_H
#define UTILS_H

#include "appGlobals.h"

class Actor;

class ScopedSignalBlocker
{
public:
    ScopedSignalBlocker(QObject* pObject);
    ~ScopedSignalBlocker();
private:
    QObject* m_pObject;
};

QPixmap generateImageTumbnail(const QImage& image, int tumbWidth = 64, int tumbHeight = 64, 
	const QRect& frameRect = QRect());

// Tree widget utils
template <typename TreeWidgetItemSubclass, typename Object>
TreeWidgetItemSubclass* treeWidgetItemFromObject(Object* pObject, QTreeWidget* pTreeWidget)
{
	TreeWidgetItemSubclass* result = 0;

	QTreeWidgetItemIterator iter(pTreeWidget);
	while(*iter)
	{
		TreeWidgetItemSubclass* pItem = static_cast<TreeWidgetItemSubclass*>(*iter);
		if(pItem->object == pObject)
		{
			result = pItem;
			break;
		}
		++iter;
	}

	return result;
}

template <typename TreeWidgetItemSubclass, typename Object> 
QPointer<Object> objectFromTreeWidgetItem(QTreeWidgetItem* pItem)
{
	if(!pItem)
	{
		return QPointer<Object>();
	}

	TreeWidgetItemSubclass* pSubclassItem = static_cast<TreeWidgetItemSubclass*>(pItem);
	Q_ASSERT(pSubclassItem);
	return pSubclassItem->object;
}


#endif // UTILS_H
